<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>Apollo学习 - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="Apollo学习">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content="Apollo学习 - 天地维杰网" />
    <meta name="description" content="Apollo（阿波罗）是携程框架部门研发的分布式配置中心，能够集中化管理应用不同环境、不同集群的配置，配置修改后能够实时推送到应用端，并且具备规范的权限、流程治理等特性，适用于微服务配置管理场景" />
     
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/learn-about-apollo/" itemprop="url">
        Apollo学习
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2021-02-25">
    2021-02-25
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/middleware" itemprop="url" rel="index">
        <span itemprop="name">middleware</span>
      </a>
      &nbsp; 
    </span>
  
</span>


      
 <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">原创</span>
</span>

       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">2844 字 ~6分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    

<h2 id="1-概念">1. 概念</h2>

<p><a href="https://ctripcorp.github.io/apollo/#/zh/README">https://ctripcorp.github.io/apollo/#/zh/README</a></p>

<blockquote>
<p>Apollo（阿波罗）是携程框架部门研发的分布式配置中心，能够集中化管理应用不同环境、不同集群的配置，配置修改后能够实时推送到应用端，并且具备规范的权限、流程治理等特性，适用于微服务配置管理场景</p>
</blockquote>

<h2 id="2-组件">2.组件</h2>

<p>架构视图</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144033.png" width = 900 /> </div>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144057.png" width = 900 /> </div>

<h3 id="2-1-configservice">2.1 ConfigService</h3>

<p>• 配置获取接口
• 配置推送接口
• 服务Apollo客户端</p>

<h3 id="2-2-adminservice">2.2 AdminService</h3>

<p>• 配置管理接口
• 配置修改、发布接口
• 服务Portal</p>

<h3 id="2-3-metaserver-包装服务列表">2.3 MetaServer 包装服务列表</h3>

<p>• Portal通过域名访问Meta Server获取Admin Service服务列表
• Client通过域名访问Meta Server获取Config Service服务列表
• 相当于一个Eureka Proxy
• 逻辑角色，和Config Service部署在一起</p>

<p><a href="https://www.jianshu.com/p/12ae8455d48a">MetaServer的作用说明</a>，按文档的分析就是MetaServer的作用是包装euraka采集的 ConfigService和AdminService的信息，然后交给Portal用来展示或者做其他的事情。</p>

<h3 id="2-4-eureka-服务注册与发现">2.4 Eureka 服务注册与发现</h3>

<p>• 服务注册和发现
• Config/AdminService注册并心跳
• 和ConfigService部署在一起</p>

<h3 id="2-5-portal-配置管理界面">2.5 Portal 配置管理界面</h3>

<p>• 配置管理界面
• 通过Meta Server获取AdminService服务列表
• 客户端软负载</p>

<h3 id="2-6-client客户端">2.6 Client客户端</h3>

<p>• 应用获取配置，实时更新
• 通过Meta Server获取Config Service服务列表
• 客户端软负载（客户端负载均衡指的是把负载均衡的功能以库的方式集成到服务的消费方，而不再是由一台指定的负载均衡设备集中提供。）</p>

<h2 id="3-部署">3.部署</h2>

<h3 id="3-1-docker方式快速部署">3.1 docker方式快速部署</h3>

<p>安装docker步骤略过
1. 首先克隆 apollo的项目</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">```
https://gitee.com/nobodyiam/apollo
```</code></pre></div>
<ol>
<li><p>进入<code>apollo/scripts/docker-quick-start</code> 目录 ，然后执行 <code>docker-compose up</code> 命令</p>

<blockquote>
<p>Compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose，您可以使用 YML 文件来配置应用程序需要的所有服务。然后，使用一个命令，就可以从 YML 文件配置中创建并启动所有服务。</p>
</blockquote>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144113.png" width = 900 /> </div>
    

<p>出现了started，you can visit ，就已经是启动成功了</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144126.png" width = 900 /> </div>

<p>docker 控制台也可以看到相应的应用</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144205.png" width = 900 /> </div>

<p>访问返回的地址<code>http://localhost:8070</code> 即可进入相应的页面，初始用户名apollo，密码admin</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144221.png" width = 900 /> </div>
    

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144235.png" width = 900 /> </div></li>
</ol>

<h3 id="3-2-分布式部署">3.2 分布式部署</h3>

<p><a href="https://ctripcorp.github.io/apollo/#/zh/deployment/distributed-deployment-guide">官方分布式部署文档</a></p>

<h4 id="3-2-1-本地使用docker的centos进行部署测试">3.2.1 本地使用docker的centos进行部署测试</h4>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">拉取镜像
docker pull centos:7
启动容器
docker run  -itd --privileged -p 20010:22 --name=&#34;centos-apollo&#34;  5e35e350aded    /usr/sbin/init
启动窗口后即可进入容器进行操作
docker exec -it 5171c1cdadcb /bin/bash</code></pre></div>
<h4 id="3-2-2-安装常用工具">3.2.2 安装常用工具</h4>

<ol>
<li><p>安装常用工具</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">yum install -y openssh-server vim lrzsz wget gcc-c++ pcre pcre-devel zlib zlib-devel ruby openssl openssl-devel patch bash-completion zlib.i686 libstdc++.i686 lsof unzip zip</code></pre></div></li>

<li><p>service安装</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">yum install initscripts  </code></pre></div></li>

<li><p>ifconfig安装</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">yum install net-tools.x86_64</code></pre></div></li>

<li><p>ssh安装(10.0.75.1为docker的ip)</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">sshd rpm -qa <span style="color:#000;font-weight:bold">|</span> grep ssh
yum install openssh-server 
service sshd restart
<span style="color:#8f5902;font-style:italic">#查看是否启动22端口</span> 
netstat -antp <span style="color:#000;font-weight:bold">|</span> grep sshd
	<span style="color:#4e9a06">`</span><span style="color:#4e9a06">`</span><span style="color:#4e9a06">`</span>

<span style="color:#8f5902;font-style:italic">#### 3.2.3 centos登录设置</span>
1. 修改sshd_config 为密码登录
   	</code></pre></div>
<p>shell
vim /etc/ssh/sshd_config
#打开注释 PermitRootLogin yes, 允许密码登录,保存退出</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">   		
2. 设置root用户密码
    </code></pre></div>
<p>passwd root</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">    	
3. 换个服务器远程登录
   </code></pre></div>
<p>shell
ssh root@47.52.134.16 -p 5022</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">        
以上三点参考文档
https://www.cnblogs.com/hcl1991/p/10599361.html


#### 3.2.4 同步文件到容器内目录
使用docker cp命令同步apollo需要使用的宿主机文件到容器中 [宿主机拷文件到docker容器里面](https://blog.csdn.net/wejack/article/details/114281424)</code></pre></div></li>
</ol>

<p>domino@localhost Downloads % docker cp apollo-adminservice-1.8.1-github.zip e6ed3239253a:/root/soft
domino@localhost Downloads % docker cp apollo-configservice-1.8.1-github.zip e6ed3239253a:/root/soft
domino@localhost Downloads % docker cp apollo-portal-1.8.1-github.zip e6ed3239253a:/root/soft</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">#### 3.2.5 安装java

参考[使用yum方式给centos安装 java](https://blog.csdn.net/wejack/article/details/114265570
)</code></pre></div>
<p>shell	
#列出参安装的java版本
[root@e6ed3239253a /]# yum -y list java*
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
    * base: mirrors.163.com
    * extras: mirrors.163.com
    * updates: mirrors.ustc.edu.cn
Available Packages
java-1.6.0-openjdk.x86_64                                             1:1.6.0.41-1.13.13.1.el7_3                               base
java-1.8.0-openjdk.x86_64                                             1:1.8.0.282.b08-1.el7_9                                  updates</p>

<p>我这安装的是1.8版本的jdk
[root@e6ed3239253a /]# yum -y install java-1.8.0-openjdk.x86_64
Complete!</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">#### 3.2.6 将centos容器实例打为镜像，然后以此为基础创建多服务器实例
打镜像时要注意，镜像的名称必须为小写，否则会创建失败，打包可参考文档 [docker容器打包成镜像](https://blog.csdn.net/wejack/article/details/114281625)

`docker commit -m &#34;镜像说明&#34; 容器id 镜像名:标签`</code></pre></div>
<p>shell
Downloads % docker commit -m &ldquo;apollo_centos_base&rdquo; e6ed3239253a apollo_centos_base:2.0
sha256:1dc673d6d41a057207e8f32a99daa6e454c3b2320b22e8d8bf72b1e0e43649c0
Downloads % docker images
REPOSITORY                            TAG       IMAGE ID       CREATED          SIZE
apollo_centos_base                    2.0       1dc673d6d41a   33 seconds ago   886MB</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">我使用这个基础centos镜像创建了三个centos的容器，两个分别代表两个apollo的 configservice和admin service的环境，第三个安装apollo的portal
    </code></pre></div>
<p>shell<br />
docker run  -itd &ndash;privileged -p 20011:22 &ndash;name=&ldquo;centos-apollo-trunk&rdquo;  1dc673d6d41a    /usr/sbin/init
docker run  -itd &ndash;privileged -p 20012:22 &ndash;name=&ldquo;centos-apollo-neibu&rdquo;  1dc673d6d41a    /usr/sbin/init
docker run  -itd &ndash;privileged -p 20013:22 &ndash;name=&ldquo;centos-apollo-portal&rdquo;  1dc673d6d41a    /usr/sbin/init</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">&lt;div  align=&#34;center&#34;&gt;&lt;img src=&#34;https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144254.png&#34; width = 900 /&gt; &lt;/div&gt;

#### 3.2.7 创建数据库
docker创建mysql数据库步骤略过，创建库所需要的sql在github项目中，数据库名与数据库文件名一致，每个环境要创建对应环境的数据库</code></pre></div>
<p>scripts/sql/apolloconfigdb.sql
scripts/sql/apolloportaldb.sql
```</p>

<p>我分别创建了一个trunk环境的apolloconfig库（开发环境），一个neibu环境的apolloconfig库（测试环境）,和一个portal库</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144304.png" width = 900 /> </div>

<h4 id="3-2-7-分别配置各个容器内的服务的配置文件">3.2.7 分别配置各个容器内的服务的配置文件</h4>

<ol>
<li><p>trunk与neibu的adminservice和configservice解压和配置，两个环境的操作类似</p>

<ul>
<li><p>解压项目文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">~ % docker <span style="color:#204a87">exec</span> -it b0c18e04453c /bin/bash
unzip ./apollo-adminservice-1.8.1-github.zip  -d /root/app/apollo-adminservice/
<span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c /<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># cd /root/soft</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c soft<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># unzip ./apollo-adminservice-1.8.1-github.zip  -d /root/app/apollo-adminservice/</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c soft<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># unzip ./apollo-configservice-1.8.1-github.zip  -d /root/app/apollo-configservice/</span></code></pre></div></li>

<li><p>修改配置文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#8f5902;font-style:italic">#adminservice 数据库配置</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c soft<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic">#vi apollo-adminservice/config/application-github.properties</span>
<span style="color:#8f5902;font-style:italic"># DataSource</span>
spring.datasource.url <span style="color:#ce5c00;font-weight:bold">=</span> jdbc:mysql://10.155.7.65:3306/ApolloConfigDB_trunk?characterEncoding<span style="color:#ce5c00;font-weight:bold">=</span>utf8
spring.datasource.username <span style="color:#ce5c00;font-weight:bold">=</span> root
spring.datasource.password <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#0000cf;font-weight:bold">123456</span>
        
<span style="color:#8f5902;font-style:italic">#configservice 数据库配置</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c app<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># vi apollo-configservice/config/application-github.properties</span>
<span style="color:#8f5902;font-style:italic"># DataSource</span>
spring.datasource.url <span style="color:#ce5c00;font-weight:bold">=</span> jdbc:mysql://10.155.7.65:3306/ApolloConfigDB_trunk?characterEncoding<span style="color:#ce5c00;font-weight:bold">=</span>utf8
spring.datasource.username <span style="color:#ce5c00;font-weight:bold">=</span> root
spring.datasource.password <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#0000cf;font-weight:bold">123456</span>
        </code></pre></div></li>

<li><p>配置完后就可以分别启动adminservice和configservice</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c app<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># /root/app/apollo-configservice/scripts/startup.sh</span>
Tue Mar  <span style="color:#0000cf;font-weight:bold">2</span> 07:01:26 UTC <span style="color:#000">2021</span> <span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">Starting</span> <span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span>
Application is running as root <span style="color:#ce5c00;font-weight:bold">(</span>UID 0<span style="color:#ce5c00;font-weight:bold">)</span>. This is considered insecure.
Started <span style="color:#ce5c00;font-weight:bold">[</span>750<span style="color:#ce5c00;font-weight:bold">]</span>
Waiting <span style="color:#204a87;font-weight:bold">for</span> server startup./r...    .
Tue Mar  <span style="color:#0000cf;font-weight:bold">2</span> 07:01:57 UTC <span style="color:#0000cf;font-weight:bold">2021</span> Server started in <span style="color:#0000cf;font-weight:bold">30</span> seconds!
<span style="color:#ce5c00;font-weight:bold">[</span>root@b0c18e04453c app<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># /root/app/apollo-adminservice/scripts/startup.sh</span>
Tue Mar  <span style="color:#0000cf;font-weight:bold">2</span> 07:02:06 UTC <span style="color:#000">2021</span> <span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">Starting</span> <span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#ce5c00;font-weight:bold">=</span>
Application is running as root <span style="color:#ce5c00;font-weight:bold">(</span>UID 0<span style="color:#ce5c00;font-weight:bold">)</span>. This is considered insecure.
Started <span style="color:#ce5c00;font-weight:bold">[</span>955<span style="color:#ce5c00;font-weight:bold">]</span>
Waiting <span style="color:#204a87;font-weight:bold">for</span> server startup.......
Tue Mar  <span style="color:#0000cf;font-weight:bold">2</span> 07:02:41 UTC <span style="color:#0000cf;font-weight:bold">2021</span> Server started in <span style="color:#0000cf;font-weight:bold">35</span> seconds!</code></pre></div></li>
</ul></li>

<li><p>portal环境配置</p>

<ul>
<li><p>解压portal项目文件到目录</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@24556e6e825e /<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># unzip /root/soft/apollo-portal-1.8.1-github.zip  -d /root/app/apollo-portal</span>
Archive:  /root/soft/apollo-portal-1.8.1-github.zip
    creating: /root/app/apollo-portal/config/
    creating: /root/app/apollo-portal/scripts/
    inflating: /root/app/apollo-portal/scripts/startup.sh
    inflating: /root/app/apollo-portal/apollo-portal-1.8.1.jar
    inflating: /root/app/apollo-portal/scripts/shutdown.sh
    inflating: /root/app/apollo-portal/config/app.properties
    inflating: /root/app/apollo-portal/apollo-portal-1.8.1-sources.jar
    inflating: /root/app/apollo-portal/apollo-portal.conf
    inflating: /root/app/apollo-portal/config/apollo-env.properties
    inflating: /root/app/apollo-portal/config/application-github.properties</code></pre></div></li>

<li><p>配置portal项目配置文件</p>

<p>修改portal数据库配置文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@24556e6e825e /<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># vi /root/app/apollo-portal/config/application-github.properties</span>
<span style="color:#8f5902;font-style:italic"># DataSource</span>
spring.datasource.url <span style="color:#ce5c00;font-weight:bold">=</span> jdbc:mysql://10.155.7.65:3306/ApolloPortalDB?characterEncoding<span style="color:#ce5c00;font-weight:bold">=</span>utf8
spring.datasource.username <span style="color:#ce5c00;font-weight:bold">=</span> root
spring.datasource.password <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#0000cf;font-weight:bold">123456</span></code></pre></div>
<p>portal自定义的环境是dev环境，在 apolloportaldb的 serviceconfig表中 的 key值为apollo.portal.envs 的值中定义了相应的环境，默认只有一个dev,需要改成需要的环境，我改为了trunk,neibu</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330145836.png" width = 900 /> </div>
    

<p>修改环境配置文件，将需要的环境配置到apollo-env.properties文件中 .meta前的字符与环境相同</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">[root@24556e6e825e /]# vi /root/app/apollo-portal/config/apollo-env.properties
local.meta=http://localhost:8080
trunk.meta=http://172.17.0.5:8080
neibu.meta=http://172.17.0.6:8080</code></pre></div></li>

<li><p>启动服务
配置好以后就可以启动portal项目了，然后通过docker机的ip+项目端口就可以访问portal的服务了</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">[root@24556e6e825e /]# /root/app/apollo-portal/scripts/startup.sh
Tue Mar  2 07:22:20 UTC 2021 ==== Starting ====
Application is running as root (UID 0). This is considered insecure.
Started [313]
Waiting for server startup......
Tue Mar  2 07:22:51 UTC 2021 Server started in 30 seconds!</code></pre></div>
<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144330.png" width = 900 /> </div>
        

<p>使用 apollo/admin即可进行登录和使用，首次登录时右上角会有提示补缺环境的提示，然后在左下角点击补缺环境按钮，即可识别相应环境</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144345.png" width = 900 /> </div>

<blockquote>
<p>由于我的笔记本是macos的，所以无法直接访问docker容器中的ip
按照以下文章打通了宿主机和docker中的网络，可以直接通过docker中的ip访问docker内的服务
<a href="https://blog.csdn.net/wejack/article/details/114268784">https://blog.csdn.net/wejack/article/details/114268784</a>
有另外两篇设置固定ip的文章 和装docker-connector的文章 ，按文章操作后均未成功</p>
</blockquote>

<p>访问 trunk环境和neibu环境的机器ip+8080端口可以查看相应信息<br />
172.17.0.5:8080 172.17.0.6:8080</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144414.png" width = 900 /> </div>
    

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144435.png" width = 900 /> </div></li>
</ul></li>
</ol>

<p>文档可以参考apollo官方文档  <a href="https://ctripcorp.github.io/apollo/#/zh/deployment/distributed-deployment-guide?id=_311-apolloportalenvs-%e5%8f%af%e6%94%af%e6%8c%81%e7%9a%84%e7%8e%af%e5%a2%83%e5%88%97%e8%a1%a8">添加自定义的环境</a></p>

<h2 id="客户端使用">客户端使用</h2>

<p><a href="https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97#%E4%BA%94%E6%9C%AC%E5%9C%B0%E5%BC%80%E5%8F%91%E6%A8%A1%E5%BC%8F">java客户端使用说明</a></p>

<h2 id="98-开源配置中心对比矩阵">98.开源配置中心对比矩阵</h2>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220330144536.png" width = 900 /> </div>

    </div>
    <footer class="post-footer">
     
 
<div class="post-tags">     
     
    <a href="http://www.shutdown.cn/tags/apollo" rel="tag" title="apollo">#apollo#</a>
    
    <a href="http://www.shutdown.cn/tags/%e9%85%8d%e7%bd%ae%e4%b8%ad%e5%bf%83" rel="tag" title="配置中心">#配置中心#</a>
    
    <a href="http://www.shutdown.cn/tags/%e5%88%86%e5%b8%83%e5%bc%8f" rel="tag" title="分布式">#分布式#</a>
    
    <a href="http://www.shutdown.cn/tags/%e9%9b%86%e7%be%a4" rel="tag" title="集群">#集群#</a>
    
</div>



     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/compare-git-merge-no-ff-and-ff-and-squash/" rel="next" title="通过实验来比较git merge --no-ff 与--ff 和--squash的区别">
        <i class="fa fa-chevron-left"></i> 通过实验来比较git merge --no-ff 与--ff 和--squash的区别
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/lvs_keepalive_jenkins2_ha/" rel="prev" title="lvs&#43;keepalive配置Jenkins2高可用">
        lvs&#43;keepalive配置Jenkins2高可用 <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

  <ul class="sidebar-nav motion-element">
    <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
      文章目录
    </li>
    <li class="sidebar-nav-overview" data-target="site-overview">
      站点概览
    </li>
  </ul>

    <section class="site-overview sidebar-panel ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
<section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
    <div class="post-toc">
        <div class="post-toc-content"><nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#1-概念">1. 概念</a></li>
<li><a href="#2-组件">2.组件</a>
<ul>
<li><a href="#2-1-configservice">2.1 ConfigService</a></li>
<li><a href="#2-2-adminservice">2.2 AdminService</a></li>
<li><a href="#2-3-metaserver-包装服务列表">2.3 MetaServer 包装服务列表</a></li>
<li><a href="#2-4-eureka-服务注册与发现">2.4 Eureka 服务注册与发现</a></li>
<li><a href="#2-5-portal-配置管理界面">2.5 Portal 配置管理界面</a></li>
<li><a href="#2-6-client客户端">2.6 Client客户端</a></li>
</ul></li>
<li><a href="#3-部署">3.部署</a>
<ul>
<li><a href="#3-1-docker方式快速部署">3.1 docker方式快速部署</a></li>
<li><a href="#3-2-分布式部署">3.2 分布式部署</a>
<ul>
<li><a href="#3-2-1-本地使用docker的centos进行部署测试">3.2.1 本地使用docker的centos进行部署测试</a></li>
<li><a href="#3-2-2-安装常用工具">3.2.2 安装常用工具</a></li>
<li><a href="#3-2-7-分别配置各个容器内的服务的配置文件">3.2.7 分别配置各个容器内的服务的配置文件</a></li>
</ul></li>
</ul></li>
<li><a href="#客户端使用">客户端使用</a></li>
<li><a href="#98-开源配置中心对比矩阵">98.开源配置中心对比矩阵</a></li>
</ul></li>
</ul>
</nav></div>
    </div>
</section>

  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>